package com.yijia.work4.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class Question4Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession();

        if (request.getParameter("address") == "" || request.getParameter("address") == null) {
            session.setAttribute("error", "内容为空！");
            request.getRequestDispatcher("/work4/4.jsp").forward(request, response);
            System.out.println("输入的内容为空！！！");
        } else {
            session.setAttribute("address", request.getParameter("address"));
            request.getRequestDispatcher("/work4/4.jsp").forward(request, response);
            System.out.println("文本域输入的内容是：" + request.getParameter("address"));
        }


    }
}
